#include "ring_queue.hpp"
#include "Task.hpp"
#include<ctime>
#include<unistd.h>

void* consumer(void* c)
{
	RingQueue<Task>* rq = (RingQueue<Task>*)c;
	while(1)
	{
		Task t;
		rq->Get(&t);

		int result = t.Handler();
		std::cout<<"消费者：Task Done. Result:"<<result << std::endl;
		
	}
	return nullptr;
}
void* productor(void* p)
{
	RingQueue<Task>* rq = (RingQueue<Task>*)p;
	while(1)
	{
		int top = rand()%20;
		Task t(top);
		t.Show();
		rq->Put(t);
		sleep(1);
	}
	return nullptr;
}
int main()
{
	RingQueue<Task>* rq = new RingQueue<Task>(10);

	pthread_t c,p;
	pthread_create(&c,nullptr,consumer,rq);
	pthread_create(&p,nullptr,productor,rq);

	pthread_join(c,nullptr);
	pthread_join(p,nullptr);
	return 0;
}
